#-------------------------------------------------------------------------------
# Name:       pdf_converter_windows.py
# Purpose:    Convert pdf to image files
#
# Authors:    John Graves <john.graves@slidespeech.com>
#
# Copyright:  (c) Slidespeech Ltd 2012
# Licence:    MIT license
#-------------------------------------------------------------------------------

import os
import subprocess

class PDFConfig:
    pdfExe = "convertk.cmd" # d:\ImageMagick-6.8.0-Q16\convert.exe %1 %2 %3 %4 %5 %6
    dependencies = [pdfExe]
    # To avoid conflict with
    # C:\Windows\System32\convert.exe

def pdfToPng(pdfPath, imagePath, pdfFile='contents.pdf', imageFile='slide.png'):
    try:
        ret = subprocess.call([PDFConfig.pdfExe, '-density', '200', \
                     os.path.join(pdfPath, pdfFile), \
                     '-resize', '25%', \
                     os.path.join(imagePath, imageFile)])
    except Exception as ex:
        raise RuntimeError("Could not generate images, {0} failed".format(PDFConfig.pdfExe))

    if ret:
        raise RuntimeError("Could not generate images, {0} failed".format(PDFConfig.pdfExe))

    return ret
